package com.crl.net.io
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.utils.ByteArray;
	
	public class ServerStream
	{
		public function ServerStream()
		{
			super();
		}
		
		public function decode(file:File):ByteArray{
			var bytes:ByteArray;
			
			var stream:FileStream=new FileStream();
			try{
				stream.open(file,FileMode.READ);
				readBytes(bytes,0,stream.bytesAvailable);
			}catch(e:Error){
				
			}
			finally{
				stream.close();
			}
			return bytes;
		}
		
		public function encode(bytes:ByteArray,file:File):Boolean{
			var stream:FileStream=new FileStream();
			
			var result:Boolean=false;
			try{
				stream.open(file,FileMode.WRITE);
				stream.writeBytes(bytes,0,bytes.bytesAvailable);
				result=true;
			}catch(e:Error){
				
			}
			finally{
				stream.close();
			}
			return result;
		}
	}
}